<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">

<head>

    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <meta name="description" content=""/>
    <meta name="author" content=""/>

    <title>分配权限</title>

    <!-- Bootstrap Core CSS -->
    <link th:href="@{/vendor/bootstrap/css/bootstrap.min.css}" rel="stylesheet"/>

    <!-- MetisMenu CSS -->
    <link th:href="@{/vendor/metisMenu/metisMenu.min.css}" rel="stylesheet"/>

    <!-- Custom CSS -->
    <link th:href="@{/dist/css/sb-admin-2.css}" rel="stylesheet"/>

    <!-- Custom Fonts -->
    <link th:href="@{/vendor/font-awesome/css/font-awesome.min.css}" rel="stylesheet" type="text/css"/>

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

<div id="wrapper">

    <div th:include="navigation :: copy"></div><!-- 引用导航栏模板 -->

    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">分配角色</h1>
            </div>
            <!-- /.col-lg-12 -->
        </div>

        <div>
            <table class="table table-hover">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>用户名</th>
                    <th>分配角色</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="obj : ${datas}" th:if="${#authentication.name}!=${obj.username}"><!--  不修改自己角色，因此隐藏自己的 -->
                    <td th:text="${obj.id}">${obj.id}</td>
                    <td th:text="${obj.username}">${obj.username}</td>
                    <td>
                        <input type="checkbox" th:each="role : ${roles}" th:value ="${role.id}" th:text="${role.name}" th:checked="${obj.hasRole(role)}"
                        th:onclick="'editRoles(this.value,'+${obj.id}+',this.checked);'"
                        />
                    </td>
                </tr>
                </tbody>
            </table>
            <div th:include="page :: pager" th:remove="tag"></div>
        </div>
    </div>
    <!-- /#page-wrapper -->

</div>
<!-- /#wrapper -->

<!-- jQuery -->
<script th:src="@{/vendor/jquery/jquery.min.js}"></script>

<!-- Bootstrap Core JavaScript -->
<script th:src="@{/vendor/bootstrap/js/bootstrap.min.js}"></script>

<!-- Metis Menu Plugin JavaScript --><!-- 多级菜单用的。。。吧 -->
<script th:src="@{/vendor/metisMenu/metisMenu.min.js}"></script>

<!-- Custom Theme JavaScript -->
<script th:src="@{/dist/js/sb-admin-2.js}"></script>

<script>
    function editRoles(rid, uid, state) {
        alert(rid + uid + state);
        $.ajax({
            url:'/editRoles',
            type:'GET',
            data:{rid:rid,uid:uid,state:state},
            success:function(result){
                //成功回调
            },
            error:function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.readyState+textStatus.toString()+errorThrown.toString());
            }
        });
    }

</script>

</body>

</html>
